package com.xianzhiOA.controller;

import com.xianzhiOA.bean.XzComment;
import com.xianzhiOA.service.XzCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/4/19.
 */
@Controller
@RequestMapping("/Comment")
public class XzCommentController extends BaseController{
    @Autowired
    private XzCommentService commentService;

    @RequestMapping("/addComment.do")
    public ModelAndView addComment(XzComment comment, RedirectAttributes redirectAttributes){
        ModelAndView mv = new ModelAndView("redirect:/Person/editComment.do");
        Date date = new Date();
        comment.setCreateTime(date);
        redirectAttributes.addAttribute("personId",comment.getPersonId());
        commentService.insertComment(comment);
        return  mv;
    }

    @RequestMapping("/selCommentExist.do")
    @ResponseBody
    public Map<String,Object> selCommentExist(Long personId){
        Map<String,Object> map = new HashMap<>();
        int i = commentService.selectCommentExist(personId);
        if(i>0){
            map.put("msg","yes");
        }else{
            map.put("msg","no");
        }
        return  map;
    }
}
